package com.shuoyue.ycgk.ui.estimate;

import android.text.Html;

import androidx.annotation.Nullable;

import com.chad.library.adapter.base.BaseViewHolder;
import com.shuoyue.ycgk.R;
import com.shuoyue.ycgk.base.baseadapter.AppBaseQuickAdapter;
import com.shuoyue.ycgk.entity.Estimate;
import com.shuoyue.ycgk.utils.XDateUtils;

import java.util.List;

public class EstimateAdapterDateable extends AppBaseQuickAdapter<Estimate> {
    public EstimateAdapterDateable(@Nullable List<Estimate> data) {
        super(R.layout.item_estimate, data);
    }


    @Override
    protected void convert(BaseViewHolder helper, Estimate item) {
        helper.addOnClickListener(R.id.start);
        helper.setText(R.id.name, item.getTitle());
        // TODO 修改字段后开出来下面的

//        helper.setText(R.id.begin_time, "估分时间: "
//                + (XDateUtils.format(item.getStartTime().getTime(), "MM月dd日 HH:mm"))
//                + "~"
//                + (XDateUtils.format(item.getEndTime().getTime(), "MM月dd日 HH:mm")));
        helper.setText(R.id.regist_num, item.getIsSign() == 1 ?
                Html.fromHtml("<font color='#06A0DC'>" + item.getUnitName() + "--" + item.getPostName() + "</font>")
                : Html.fromHtml(
                "已有"
                        +
                        "<font color='#06A0DC'>" + item.getTotalPerson() + "</font>人报名"

        ));
        if (item.getIsSign() == 0) {
            helper.setText(R.id.start, "立即报名");
            helper.setBackgroundRes(R.id.start, R.drawable.button_bg_theme);
            helper.getView(R.id.start).setEnabled(true);
//            try {
//                Date dateStart = XDateUtils.cover(item.getStartTime(), "yyyy-MM-dd HH:mm");
//                Date dateEnd = XDateUtils.cover(item.getEndTime(), "yyyy-MM-dd HH:mm");
//                long now = System.currentTimeMillis();
//                helper.getView(R.id.start).setEnabled(now < dateEnd.getTime());
//                helper.setBackgroundRes(R.id.start, now < dateEnd.getTime() ?
//                        R.drawable.button_bg_theme : R.drawable.button_bg_theme_unclickable);
//            } catch (Exception e) {
//                e.printStackTrace();
//            }
        } else if (item.getStatus() == 0) {
            helper.setText(R.id.start, "开始估分");
            try {
//                Date dateStart = XDateUtils.cover(item.getStartTime(), "yyyy-MM-dd HH:mm:ss");
//                Date dateEnd = XDateUtils.cover(item.getEndTime(), "yyyy-MM-dd HH:mm");
                long now = System.currentTimeMillis();
                // TODO 修改字段后开出来下面的
//                helper.getView(R.id.start).setEnabled(now > item.getStartTime().getTime());
//                helper.setBackgroundRes(R.id.start, now > item.getStartTime().getTime() ?
//                        R.drawable.button_bg_theme : R.drawable.button_bg_theme_unclickable);
//                helper.setText(R.id.start, now > item.getStartTime().getTime() ? "开始估分" : "请等待");

            } catch (Exception e) {
                e.printStackTrace();
            }
        } else {
            helper.setBackgroundRes(R.id.start, R.drawable.button_bg_orange);
            helper.getView(R.id.start).setEnabled(true);
            helper.setText(R.id.start, "查看排行");
        }
    }
}
